The Cartesian, Funnel, and Pie charting types in NOV Chart for .NET also support a 3D view of the data contained in them. This topic discusses how to switch a chart to a 3D view and shows how to control the projection and lighting applied to the chart.
C# |
Copy Code
|
---|---|
nChartView.Surface.CreatePredefinedChart(Nevron.Nov.Chart.ENPredefinedChartType.Cartesian);
NCartesianChart chart = (NCartesianChart)nChartView.Surface.Charts[0];
chart.Enable3D = true;
|
That's it. Now you can also control the chart projection and lighting - the following two pictures show a simple bar chart rendered with different lighting settings:
Cartesian chart with soft lighting | Cartesian chart with metallic lighting |
The chart has a property called Projection that gives you access to different settings that control how the chart 3D model scene is projected on the screen. This includes settings like whether the projection is perspective or orthogonal, the camera position (elevation and rotation relative to the chart), and others. In addition, you can also choose from a set of predefined projections using the SetPrededfinedProjection method of the NProjection object:
C# |
Copy Code
|
---|---|
NChart chart = nChartView.Surface.Charts[0];
chart.Enable3D = true;
chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted);
|
Another object that affects the chart appearance in 3D is the light model object, which is accessible from the LightModel property. This object controls how light sources interact with the chart scene to produce more realistic lighting effects. The following code shows how to enable lighting and how to apply a predefined light source configuration:
C# |
Copy Code
|
---|---|
NChart chart = nChartView.Surface.Charts[0];
chart.LightModel.EnableLighting = true;
chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.ShinyTopLeft);
|
The above code creates a light model with a single point light source. You can create your own light source configuration by adding one or more light sources to the light model's LightSources collection. The following code shows how to add a point light source to the scene and modify its Ambient, Diffuse and Specular colors:
C# |
Copy Code
|
---|---|
NChart chart = nChartView.Surface.Charts[0]; chart.LightModel.EnableLighting = true; chart.LightModel.GlobalAmbientColor = new NColor(60, 60, 60); NPointLightSource pointLightSource = new NPointLightSource(); pointLightSource.AmbientColor = new NColor(64, 64, 64); pointLightSource.DiffuseColor = new NColor(255, 255, 255); pointLightSource.SpecularColor = new NColor(64, 64, 64); pointLightSource.Position = new NVector3DF(100.0f, 150.0f, 300.0f); chart.LightModel.LightSources.Add(pointLightSource); |
You can add instances of the following objects to the LightSources collection:
Light Source | Description |
NPointLightSource |
This is a light source that emits light in all directions from a single point in space, similar to a light bulb or a candle. |
NDirectionalLightSource | This is a light source that emits light in a specific direction, as if it is coming from an infinitely distant source, like the sun. |
NSpotLightSource |
This is a light source that emits light from a single point in space, but the light is visible only from a specified direction like the light coming from a desk lamp or car headlights. |
All three light sources emit light that consists of different components:
Light Source Property | Description |
Ambient |
The ambient component represents the contribution of the light source to the overall level of lighting in the scene. It is independent of the position or direction of the light source. |
Diffuse | The diffuse component represents the component of the light source that is scattered by the reflecting surface in all directions. It is proportional to the angle between the surface normal and the direction of the incoming light. It is used to simulate the way light interacts with matte or rough surfaces. |
Specular |
The specular component represents the way light is reflected by a surface in a specific direction. It is proportional to the angle between the direction of the reflected light and the direction of the viewer. It is used to simulate the way light interacts with shiny or smooth surfaces. |